package stu.day9_day18;

import java.util.*;

public class train3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());
        int len = Integer.parseInt(sc.nextLine());

        ArrayList<String> list = new ArrayList<>();
        for(int i=0;i<len;i++){
            list.add(sc.nextLine());
        }

        StringBuilder sb = new StringBuilder();
        int la = list.get(num).length();
        char ch = list.get(num).charAt(la-1);
        sb.append(list.get(num));
        list.remove(num);

        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                if(o1.length()==o2.length()){
                    return o1.compareTo(o2);
                }else {
                return o2.length()-o1.length();
                }
            }
        });

        boolean index = true;

        while (index){
            int xx = 0;
            for (int i=0;i<list.size();i++){
                int length = list.get(i).length();
                if(list.get(i).charAt(0)==ch){
                    sb.append(list.get(i));
                    ch = list.get(i).charAt(length-1);
                    list.remove(i);
                    xx = 1;
                    break;
                }
            }
            if (xx==0){
                index =false;
            }
        }

        System.out.println(sb.toString());


    }
}
